package net.test.piggy.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitDelayHandler {

    Logger logger = LoggerFactory.getLogger(RabbitDelayHandler.class);
    @RabbitListener(bindings = @QueueBinding(value = @Queue("piggy-dead-letter-queue"),
            exchange = @Exchange("piggy.dead.letter.exchange"), key = ("dead_letter")))
    public void receiveDeadMessage(Object object){
        Message message = (Message) object;
        byte[] body = message.getBody();
        String string = new String(body);
        logger.info(" receive piggy-dead-letter-queue message --> {}",string);
    }

}
